//
//  FQDSwitchSettingCell.m
//  FakeQDaily
//
//  Created by mewxiv on 9/9/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDSwitchSettingCell.h"
#import "FQDSwitch.h"
#import "FQDSettingOption.h"

@interface FQDSwitchSettingCell ()

@property (nonatomic, strong) FQDSwitch *switchControl;

@end

@implementation FQDSwitchSettingCell
@synthesize option = _option;

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self prepareSettingUI];
    }
    return self;
}

- (void)prepareSettingUI
{
    CGRect switchFrame = CGRectMake(0, 0, 40.0f, 20.0f);
    _switchControl = [[FQDSwitch alloc] initWithFrame:switchFrame];
    self.accessoryView = _switchControl;
}

- (void)setOption:(FQDSettingOption *)option
{
    _option = option;
    self.textLabel.text = option.title;
    
    if (option.icon) {
        UIImage *iconImage = [UIImage imageNamed:option.icon];
        self.imageView.image = iconImage;
    }
    [self.switchControl setOn:[option.value boolValue]];
}

+ (NSString *)reuseId
{
    return @"FQDSwitchSettingCell";
}

@end
